<template>
	<view style="margin-bottom: 20rpx;">
		<uni-forms label-width="105px" label-position="top" style="padding-bottom: 100rpx;">
			<uni-notice-bar single text="-1代表 不参与测评。不会生成报告"></uni-notice-bar>


			<uni-section title="客户信息" type="circle" padding>
				<view class="">

					<view style="font-size: 34rpx;font-weight: bold;margin-bottom: 10rpx;">
						{{ editData.student.name }}
					</view>

					{{ editData.axParentsDO.phone }}&nbsp;&nbsp;|&nbsp;&nbsp;
					{{ dateToAge(editData.student.dateOfBirth)}}&nbsp;&nbsp;|&nbsp;&nbsp;{{editData.student.sex == 0?'女':'男'}}


					<uni-row>
						<uni-col :span="12">
							<uni-forms-item label="身高(cm)">
								<uni-easyinput :clearable="false" v-model="editData.student.height" :min="-1"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>


						<uni-col :span="12">
							<uni-forms-item label="体重(kg)" prop="grade">
								<uni-easyinput :clearable="false" v-model="editData.student.weight"
									style="width: 250rpx;"></uni-easyinput>
							</uni-forms-item>
						</uni-col>

					</uni-row>
				</view>
			</uni-section>



			<uni-section title="小儿神经心理发育检查表" type="circle" padding>
				<view class="">
					<uni-row>
						<uni-col :span="12">
							<uni-forms-item label="大运动" prop="grade">
								<uni-easyinput :clearable="false" type="number" v-model="editData.fyDyd" :min="-1"
									style="width: 150px;" label="描述文字"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="精细运动" prop="grade">
								<uni-easyinput :clearable="false" type="number" v-model="editData.fyJxyd" :min="-1"
									style="width: 150px;" label="描述文字"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="适应能力" prop="grade">
								<uni-easyinput :clearable="false" type="number" v-model="editData.fySynl" :min="-1"
									style="width: 150px;" label="描述文字"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="语言表达" prop="grade">
								<uni-easyinput :clearable="false" type="number" v-model="editData.fyYybd" :min="-1"
									style="width: 150px;" label="描述文字"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="社交行为" prop="grade">
								<uni-easyinput :clearable="false" type="number" v-model="editData.fySjxw" :min="-1"
									style="width: 150px;" label="描述文字"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
					</uni-row>

				</view>
			</uni-section>



			<uni-section title="感觉统合发展评量表" type="circle" padding>
				<view class="">
					<uni-row>
						<uni-col :span="12">
							<uni-forms-item label="前庭觉" prop="grade">
								<uni-easyinput :clearable="false" type="number" v-model="editData.gtQtphg" :min="-1"
									style="width: 150px;" label="描述文字"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="本体感" prop="grade">
								<uni-easyinput :clearable="false" type="number" v-model="editData.gtBtj" :min="-1"
									style="width: 150px;" label="描述文字"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
						<uni-col :span="12">
							<uni-forms-item label="触 觉" prop="grade">
								<uni-easyinput :clearable="false" type="number" v-model="editData.gtCjfyj" :min="-1"
									style="width: 150px;" label="描述文字"></uni-easyinput>
							</uni-forms-item>
						</uni-col>
					</uni-row>

				</view>
			</uni-section>


		</uni-forms>
		<view class="dialog-footer  fixed-bottom padding" style="display: flex;">

			<button class="login-btn cu-btn block bg-blue lg round margin-top-sm" style="width: 300rpx" @click="save"
				v-if="status==1">重新测评</button>
			<button class="login-btn cu-btn block bg-blue lg round margin-top-sm"
				style="width: 430rpx;margin-left: 20rpx;" @click="download" v-if="status==1">下
				载测评报告</button>

			<button class="login-btn cu-btn block bg-blue lg round margin-top-sm" style="width: 750rpx;" @click="save"
				v-if="status!=1">测评</button>
		</view>

	</view>
</template>

<script>
	import {
		doAddCp,
		getLishi,
		getById
	} from '@/api/marketing/evaluation/AxEvaluationRecordManagementApi'
	import config from '@/config'
	import {
		evaluationPlan
	} from "@/utils/common.js";
	import {
		formatTime,
		dateToAge,
		isJson,
		isNull
	} from '@/utils/validate'
	export default {
		name: 'Xq',

		data() {
			return {
				fullscreenLoading: false,
				axParentsDO: {
					phone: '',
				},
				editData: {

					student: {
						age2: '',
						height: '',
						weight: '',
						name: ''
					},
					axParentsDO: {
						phone: '',
					},
				},
				status: 0,
				asdfasdf: {}
			}
		},
		onLoad(e) {
			if (e.id != null) {
				this.editData.erid = e.id

				this.getEvaluation()
			}
		},

		methods: {
			download(row) {
				var adfas1 = ''
				var adfas2 = ''
				var mymessage = confirm("需要同时发送至家长微信吗?");
				if (mymessage == true) {

				} else {

				}


				this.getProgress(config.baseUrl + "/" + this.asdfasdf.evaluationPlanUrl, this.asdfasdf.evaluationPlanUrl
					.split('/')[this.asdfasdf
						.evaluationPlanUrl.split('/').length - 1], adfas1)

			},
			getProgress(url, aa) {
				window.open(url, '_blank');

			},
			async getEvaluation() {
				const {
					msg,
					data,
					success
				} = await getById({
					id: this.editData.erid
				})
				if (success) {
					this.asdfasdf = data
					this.showEdit(data)
				}

			},
			close() {
				this.dialogFormVisible = false;
			},
			async save() {
				let _this = this
				this.fullscreenLoading = true;
				// 处理数据
				this.handlerFormData(this.editData);

				this.editData.lishi = null
				this.editData.lishi = JSON.stringify(this.editData).replace(/[\\]/g, '');
				// 修改
				const {
					success,
					msg
				} = await doAddCp(this.editData)
				if (success) {
					uni.showModal({
						title: "测评成功",
						content: "下载按钮将出现在右下角",
						success() {
							_this.getEvaluation()
						}
					})
				}


				this.close();
			},

			// 处理 form数据
			handlerFormData(formData) {
				if (!isNull(formData)) {
					for (let key in formData) {
						// 对于时间类进行处理
						if ("[object Date]" === Object.prototype.toString.call(formData[key])) {
							formData[key] = formateDate(formData[key], 'yyyy-MM-dd hh:mm:ss');
						}
					}
				}
			},
			dateToAge(date) {
				return dateToAge(date)
			},
			async showEdit(row) {
				this.status = row.status
				this.dialogFormVisible = true
				this.editData = evaluationPlan
				this.editData.evaluationGrade = row.evaluationGrade
				this.editData.gradetype = 'xq'
				this.editData.erid = row.id
				this.editData.student.id = row.student.id
				this.editData.student.age2 = row.student.age2
				this.editData.student.height = row.student.height
				this.editData.student.weight = row.student.weight
				this.editData.student.name = row.student.name
				this.axParentsDO = row.parentsInfo // this.editData = this.common.evaluationPlan
				this.editData.student = row.student
				this.editData.axParentsDO.phone = row.parentsInfo.phone
				this.editData.student.age2 = dateToAge(
					this.editData.student.dateOfBirth
				)

				const {
					msg,
					success,
					data
				} = await getLishi({
					erid: row.id,
					evaluationGrade: this.editData.evaluationGrade
				})

				if (data.lishi != null) {
					if (!isJson(data.lishi)) {
						uni.showModal({
							title: "历史数据异常",
							content: "检测到有历史数据，但是是异常的数据。但不影响新的测评。如有需要请联系青与澜"
						})

						return
					}
					this.editData = JSON.parse(data.lishi)
					uni.showToast({
						icon: "none",
						title: "历史数据加载成功"
					})
				}
			},
		},
	}
</script>

<style scoped>
	.el-dialog__header {
		text-align: center;
	}

	.el-dialog__title {
		color: #ff0000;
		font-weight: 1000;
	}

	.uni-forms-item--small.uni-forms-item {
		margin-bottom: 18px;
		margin-left: 40px;
	}

	.uni-forms--label-top .uni-forms-item__label {
		float: none;
		padding: 0px;
		display: inline-block;
		text-align: left;
	}
</style>